import jenkins
import time

class jenkins_api_plugin(object):

    def __init__(self, jenkins_url, username, password):
        self.jenkins_url = jenkins_url
        self.username = username
        self.password = password
        self.jenkins_server = jenkins.Jenkins(self.jenkins_url, username=self.username, password=self.password)

    def get_running_jobs_num(self):
        # 获取正在运行的构建信息
        running_builds = self.jenkins_server.get_running_builds()
        return len(running_builds)

    def get_wait_build_jobs_num(self):
        # 获取构建队列中的任务列表
        queue_info = self.jenkins_server.get_queue_info()
        return len(queue_info)

    def get_executor_jobs(self):
        data = self.jenkins_server.get_running_builds()
        return data

    def stop_job(self, job_name, job_number):
        data = self.jenkins_server.stop_build(job_name, job_number)
        return data

    def delete_job_build(self, job_name, job_number):
        data = self.jenkins_server.delete_build(job_name, job_number)
        return data